package com.xnyzc.lhy.order.service.impl.sidebar;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xnyzc.lhy.common.component.redis.RedisCommon;
import com.xnyzc.lhy.common.constant.MessageConstant;
import com.xnyzc.lhy.common.constant.RedisPrefixConstant;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.penum.order.EOrderStatus;
import com.xnyzc.lhy.common.penum.tab.ETab;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.EmptyUtil;
import com.xnyzc.lhy.common.util.StringUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.dictionaries.OaSysDict;
import com.xnyzc.lhy.order.entity.order.*;
import com.xnyzc.lhy.order.entity.param.sidebar.TabResults;
import com.xnyzc.lhy.order.entity.param.sidebar.UserInfoResults;
import com.xnyzc.lhy.order.entity.result.order.Order;
import com.xnyzc.lhy.order.entity.sidebar.OaSysSidebar;
import com.xnyzc.lhy.order.entity.user.tab.OaTabPermission;
import com.xnyzc.lhy.order.entity.user.tab.OaTabUser;
import com.xnyzc.lhy.order.entity.user.wallet.OaCWallet;
import com.xnyzc.lhy.order.entity.param.sidebar.SidebarInfoResults;
import com.xnyzc.lhy.order.entity.user.OaCUser;
import com.xnyzc.lhy.order.entity.sidebar.OaCUserOffice;
import com.xnyzc.lhy.order.mapper.dictionaries.OaSysDictMapper;
import com.xnyzc.lhy.order.mapper.order.OaCOrderApprovalOfficialMapper;
import com.xnyzc.lhy.order.mapper.order.OaCOrderDeptOfficialMapper;
import com.xnyzc.lhy.order.mapper.order.OaCOrderPersonalMapper;
import com.xnyzc.lhy.order.mapper.order.OaCOrderPersonalOfficialMapper;
import com.xnyzc.lhy.order.mapper.sidebar.OaSysSidebarMapper;
import com.xnyzc.lhy.order.mapper.user.tab.OaTabPermissionMapper;
import com.xnyzc.lhy.order.mapper.user.tab.OaTabUserMapper;
import com.xnyzc.lhy.order.mapper.user.wallet.OaCWalletMapper;
import com.xnyzc.lhy.order.mapper.user.OaCUserMapper;
import com.xnyzc.lhy.order.mapper.sidebar.OaCUserOfficeMapper;
import com.xnyzc.lhy.order.mapper.sidebar.OaSysOfficeMapper;
import com.xnyzc.lhy.order.service.oss.IOaFileService;
import com.xnyzc.lhy.order.service.sidebar.SidebarService;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;


/**
 * <p>
 * 侧边栏信息 服务实现类
 * </p>
 *
 * @author lhy@xnyzc.com
 * @since 2019-07-17
 */
@Service
public class SidebarServiceImpl extends ServiceImpl<OaCUserMapper, OaCUser> implements SidebarService {

    @Autowired
    private OaCUserMapper oaCUserMapper;

    @Autowired
    private OaCWalletMapper oaCWalletMapper;

    @Autowired
    private OaCUserOfficeMapper oaCUserOfficeMapper;

    @Autowired
    private OaSysOfficeMapper oaSysOfficeMapper;

    @Autowired
    private OaSysSidebarMapper oaSysSidebarMapper;

    @Autowired
    private OaSysDictMapper oaSysDictMapper;

    @Autowired
    private OaTabUserMapper oaTabUserMapper;

    @Autowired
    private OaTabPermissionMapper oaTabPermissionMapper;

    @Autowired
    private OaCOrderApprovalOfficialMapper oaCOrderApprovalOfficialMapper;

    @Autowired
    private OaCOrderDeptOfficialMapper oaCOrderDeptOfficialMapper;

    @Autowired
    private OaCOrderPersonalMapper oaCOrderPersonalMapper;

    @Autowired
    private OaCOrderPersonalOfficialMapper oaCOrderPersonalOfficialMapper;

    @Autowired
    private RedisCommon redisCommon;

    @Autowired
    private IOaFileService iOaFileService;

    /**
     * 获取侧边栏信息
     *
     * @param userId
     * @return
     */
    @Override
    public Rv getSidebarInfo(Long userId) {
        //查询用户信息
        OaCUser user = oaCUserMapper.selectById(userId);
        if (CheckUtil.objIsEmpty(user)) {
            return Rv.wrap(EErrorCode.userInforExpire);
        }
        //查询用户钱包
        OaCWallet wallet = getWalletByUserId(user.getUserId());
        if (CheckUtil.objIsEmpty(wallet)) {
            throw PangException.create(EErrorCode.noData);
        }
        //查询部门
        OaCUserOffice office = getUserIdByDept(user.getUserId());
        String deptName = "";
        if (CheckUtil.objIsNotEmpty(office)) {
            deptName = getDeptByOfficeName(office.getOfficeId());
        }
        SidebarInfoResults results = new SidebarInfoResults();
        results.setPictureUrl("");
        results.setDeptName("");
        if (StringUtils.isEmpty(user.getUserPhone()) && user.getUserPhone().length() == 11) {
            String phoneNumber = user.getUserPhone().substring(0, 3) + "****" + user.getUserPhone().substring(7, user.getUserPhone().length());
            results.setUserPhone(phoneNumber);
        } else {
            results.setUserPhone(user.getUserPhone());
        }
        results.setDeptOfficialBalance(String.valueOf(wallet.getDeptOfficialBalance()));
        results.setIsDeptAmount(wallet.getIsDeptAmount());
        results.setPersonalOfficialBalance(String.valueOf(wallet.getPersonalOfficialBalance()));
        results.setWalletBalance(String.valueOf(wallet.getWalletBalance()));
        if (StringUtils.isNotBlank(deptName)) {
            results.setDeptName(deptName);
        }
        List<OaSysDict> dictList = getUserSidebarList(user.getUserId());
        TabResults res = new TabResults();
        List<TabResults> sidebarList = new ArrayList<>();
        for (OaSysDict dict : dictList) {
            res = new TabResults();
            res.setId(Long.valueOf(dict.getValue()));
            res.setName(dict.getLabel());
            res.setUrl("");
            if(StringUtils.isNotBlank(dict.getExpand1())){
                res.setUrl(iOaFileService.getFileUrl(Long.parseLong(dict.getExpand1())));
            }
            sidebarList.add(res);
        }
        results.setSidebarList(sidebarList);
        return Rv.wrap(EErrorCode.success, results);
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    @Override
    public Rv getSupport(String token) {
        UserInfoResults results = new UserInfoResults();
        if (StringUtils.isEmpty(token)) {
            //处理没有登录时
            results = getInfoResults();
        } else {
            List<Order> ongoingList = new ArrayList<>();
            List<Order> approvalOrderList = new ArrayList<>();
            //查询用户信息
            OaCUser user = getCUserByToken(token);
            if (CheckUtil.objIsEmpty(user)) {
                results = getInfoResults();
                return Rv.wrap(EErrorCode.userInforExpire, results);
            }
            results.setUserPhone(user.getUserPhone());
            results.setApprovalNum(0);
            results.setUserType(user.getUserType());
            results.setPersonalHint("");
            results.setApprovalHint("");
            results.setPersonalOfficialHint("");
            results.setDeptHint("");
            results.setOngoingNum(0);
            results.setOngoingPrompt("");
            results.setOngoingList(ongoingList);
            results.setApprovalList(approvalOrderList);
            Integer isHaveOrder = 0;
            Integer isArrearageOrder = 0;
            //查询tab栏并处理
            List<OaTabPermission> oaTabList = getUserTabList(user.getUserId());
            getTabList(results, oaTabList);
            List<Integer> arrearageList = new ArrayList<>();
            arrearageList.add(EOrderStatus.duringTrip.getType());
            arrearageList.add(EOrderStatus.cancelPendingPayment.getType());
            arrearageList.add(EOrderStatus.cancelOrdersFeesPaid.getType());
            //欠费订单
            List<Order> arrearageOrederList = new ArrayList<>();
            //查询审批公务订单
            List<OaCOrderApprovalOfficial> approvalOfficialList = getOrderApprovalOfficialByUserId(user.getUserId());
            if (!EmptyUtil.isEmpty(approvalOfficialList)) {
                for (OaCOrderApprovalOfficial order : approvalOfficialList) {
                    getArrearageList(arrearageList, arrearageOrederList, order.getOrderStatus(), order.getOrderNo());
                }
            }
            getApprovalOfficial(results, user);
            //查询部门公务订单
            List<OaCOrderDeptOfficial> deptOfficialList = getOrderDeptByUserId(user.getUserId());
            if (!EmptyUtil.isEmpty(deptOfficialList)) {
                for (OaCOrderDeptOfficial order : deptOfficialList) {
                    getArrearageList(arrearageList, arrearageOrederList, order.getOrderStatus(), order.getOrderNo());
                }
            }
            //查询自费叫车订单
            List<OaCOrderPersonal> personalList = getOrderPersonalByUserId(user.getUserId());
            if (!EmptyUtil.isEmpty(personalList)) {
                for (OaCOrderPersonal order : personalList) {
                    getArrearageList(arrearageList, arrearageOrederList, order.getOrderStatus(), order.getOrderNo());
                }
            }
            //查询个人公务订单
            List<OaCOrderPersonalOfficial> personalOfficialList = getOrderPersonalOfficialByUserId(user.getUserId());
            if (!EmptyUtil.isEmpty(personalOfficialList)) {
                for (OaCOrderPersonalOfficial order : personalOfficialList) {
                    getArrearageList(arrearageList, arrearageOrederList, order.getOrderStatus(), order.getOrderNo());
                }
            }
            if (EmptyUtil.isNotEmpty(arrearageOrederList)) {
                isArrearageOrder = 1;
            }
            // 正在进行中得订单
            ongoingList=getOrderOngoing(ongoingList,user);
            if(!ongoingList.isEmpty()){
                results.setOngoingList(ongoingList);
                results.setOngoingNum(ongoingList.size());
                results.setOngoingPrompt(MessageConstant.YOU_HAVE + ongoingList.size() + MessageConstant.TRIP + MessageConstant.ONGOING);
            }
            // 判断进行中的状态
            long tokenUserId = TokenUtil.getTokenUserId();
            Set<String> keys = redisCommon.keys(RedisPrefixConstant.ORDER_OA_D_ORDER + tokenUserId);
            for (String key : keys) {
                String json = redisCommon.getStr(key);
                OaCOrder parse = JSON.parseObject(json, OaCOrder.class);
                boolean aReturn = EOrderStatus.isReturn(EOrderStatus.findById(parse.getOrderStatus()));
                if (parse.getUserId().equals(tokenUserId) && aReturn) {
                    isHaveOrder = 1;
                    results.setUseOrderId(parse.getOrderNo());
                    break;
                }
            }
            results.setIsArrearageOrder(isArrearageOrder);
            results.setArrearageOrederList(arrearageOrederList);
            results.setIsHaveOrder(isHaveOrder);
            //redisKey 后续上传GPS使用
            results.setRedisKey(RedisPrefixConstant.GPS_USER_KEYP_REFIX + user.getUserId());
        }
        return Rv.wrap(EErrorCode.success, results);
    }

    public UserInfoResults getApprovalOfficial(UserInfoResults results, OaCUser user) {
        // 审批通过
        List<OaCOrderApprovalOfficial> approvalList = getApprovalOfficialByUserId(user.getUserId());
        if (!approvalList.isEmpty()) {
            List<Order> orderList = new ArrayList<>();
            for (OaCOrderApprovalOfficial approval : approvalList) {
                Order order = new Order();
                order.setOrderNo(approval.getOrderNo());
                orderList.add(order);
            }
            results.setApprovalList(orderList);
            results.setApprovalHint(MessageConstant.YOU_HAVE + approvalList.size() + MessageConstant.PEN + MessageConstant.APPROVAL_BE_USED);
            results.setApprovalNum(approvalList.size());
        }
        return results;
    }

    /**
     * 正在进行的订单
     * @param ongoingList
     * @param user
     * @return
     */
    public List<Order> getOrderOngoing(List<Order> ongoingList, OaCUser user) {
        List<OaCOrderApprovalOfficial> approvalOngoingList = getApprovalOfficialOrder(user.getUserId());
        if (!approvalOngoingList.isEmpty()) {
            for (OaCOrderApprovalOfficial approval : approvalOngoingList) {
                Order order = new Order();
                order.setOrderNo(approval.getOrderNo());
                ongoingList.add(order);
            }
        }
        List<OaCOrderPersonalOfficial> personalOfficialList = getPersonalOfficialByUserId(user.getUserId());
        if (!personalOfficialList.isEmpty()) {
            for (OaCOrderPersonalOfficial approval : personalOfficialList) {
                Order order = new Order();
                order.setOrderNo(approval.getOrderNo());
                ongoingList.add(order);
            }
        }
        List<OaCOrderPersonal> personalList = getPersonalByUserId(user.getUserId());
        if (!personalList.isEmpty()) {
            for (OaCOrderPersonal approval : personalList) {
                Order order = new Order();
                order.setOrderNo(approval.getOrderNo());
                ongoingList.add(order);
            }
        }
        List<OaCOrderDeptOfficial> deptOfficialList = getDeptOfficialByUserId(user.getUserId());
        if (!deptOfficialList.isEmpty()) {
            for (OaCOrderDeptOfficial approval : deptOfficialList) {
                Order order = new Order();
                order.setOrderNo(approval.getOrderNo());
                ongoingList.add(order);
            }
        }
        return ongoingList;
    }

    /**
     * 处理tab栏数据
     *
     * @param results
     * @param oaTabList
     * @return
     */
    public UserInfoResults getTabList(UserInfoResults results, List<OaTabPermission> oaTabList) {
        List<Order> ongoingList = new ArrayList<>();
        List<Order> approvalOrderList = new ArrayList<>();
        List<TabResults> tabList = new ArrayList<>();
        results.setApprovalNum(0);
        if (!oaTabList.isEmpty()) {
            for (int i = 0; i < oaTabList.size(); i++) {
                TabResults res = new TabResults();
                res.setId(oaTabList.get(i).getPermissionId());
                res.setName(oaTabList.get(i).getTabName());
                res.setTabId(oaTabList.get(i).getTabId());
                res.setSort(i);
                tabList.add(res);
                if (oaTabList.get(i).getTabId().equals(ETab.personal.getValue())) {
                    results.setPersonalHint(oaTabList.get(i).getTabHint());
                } else if (oaTabList.get(i).getTabId().equals(ETab.official.getValue())) {
                    results.setPersonalOfficialHint(oaTabList.get(i).getTabHint());
                } else if (oaTabList.get(i).getTabId().equals(ETab.dept.getValue())) {
                    results.setDeptHint(oaTabList.get(i).getTabHint());
                } else if (oaTabList.get(i).getTabId().equals(ETab.approval.getValue())) {
                    results.setApprovalHint(oaTabList.get(i).getTabHint());
                }
                // 进行中的提示和数量
                results.setOngoingNum(0);
                results.setOngoingPrompt("");
                // 进行和审批的集合
                results.setOngoingList(ongoingList);
                results.setApprovalList(approvalOrderList);
            }
        } else {
            OaTabPermission tab = getTabPermission();
            TabResults res = new TabResults();
            res.setName(tab.getTabName());
            res.setTabId(tab.getTabId());
            res.setId(tab.getPermissionId());
            res.setSort(0);
            results.setPersonalHint(tab.getTabHint());
            results.setApprovalHint("");
            results.setPersonalOfficialHint("");
            results.setDeptHint("");
            // 进行中的提示和数量
            results.setOngoingNum(0);
            results.setOngoingPrompt("");
            // 进行和审批的集合
            results.setOngoingList(ongoingList);
            results.setApprovalList(approvalOrderList);
            tabList.add(res);
        }
        results.setTabList(tabList);
        return results;
    }

    public UserInfoResults getInfoResults() {
        UserInfoResults results = new UserInfoResults();
        List<Order> order = new ArrayList<>();
        results.setUserPhone("");
        results.setUserType(0);
        results.setIsArrearageOrder(0);
        results.setArrearageOrederList(order);
        results.setIsHaveOrder(0);
        results.setUseOrderId("");
        List<TabResults> tabList = new ArrayList<>();
        OaTabPermission tab = getTabPermission();
        TabResults res = new TabResults();
        res.setName(tab.getTabName());
        res.setTabId(tab.getTabId());
        res.setId(tab.getPermissionId());
        res.setSort(0);
        tabList.add(res);
        results.setApprovalNum(0);
        // 4个提示
        results.setPersonalHint(tab.getTabHint());
        results.setApprovalHint("");
        results.setPersonalOfficialHint("");
        results.setDeptHint("");
        // 进行中的提示和数量
        results.setOngoingNum(0);
        results.setOngoingPrompt("");
        // 进行和审批的集合
        results.setOngoingList(order);
        results.setApprovalList(order);
        results.setTabList(tabList);
        results.setRedisKey("");
        return results;
    }


    /**
     * 通过userId查询用户tab栏
     *
     * @return
     */
    private OaTabPermission getTabPermission() {
        QueryWrapper<OaTabPermission> tabWrapper = new QueryWrapper<>();
        tabWrapper.eq(OaTabPermission.TAB_ID, 0);
        return oaTabPermissionMapper.selectOne(tabWrapper);
    }

    /**
     * 返回结果
     *
     * @return
     */
    public List<Order> getArrearageList(List<Integer> arrearageList, List<Order> arrearageOrederList, Integer orderStatus, String orderNo) {
        if (arrearageList.contains(orderStatus)) {
            Order order = new Order();
            order.setOrderNo(orderNo);
            arrearageOrederList.add(order);
        }
        return arrearageOrederList;
    }

    /**
     * 通过userId查询用户tab栏
     *
     * @param userId
     * @return
     */
    private List<OaTabPermission> getUserTabList(Long userId) {
        List<OaTabPermission> oaTabPermissionList = new ArrayList<>();
        QueryWrapper<OaTabUser> wrapper = new QueryWrapper<>();
        wrapper.eq(OaTabUser.USER_ID, userId);
        List<OaTabUser> tabList = oaTabUserMapper.selectList(wrapper);
        if (tabList != null && !tabList.isEmpty()) {
            List<Integer> tabIdList = new ArrayList<>();
            for (OaTabUser tab : tabList) {
                tabIdList.add(tab.getTabId());
            }
            QueryWrapper<OaTabPermission> tabWrapper = new QueryWrapper<>();
            tabWrapper.in(OaTabPermission.TAB_ID, tabIdList);
            tabWrapper.orderByAsc(OaTabPermission.SORT);
            oaTabPermissionList = oaTabPermissionMapper.selectList(tabWrapper);
        }
        return oaTabPermissionList;
    }


    /**
     * 通过userId查询用户侧边栏
     *
     * @param userId
     * @return
     */
    private List<OaSysDict> getUserSidebarList(Long userId) {
        List<OaSysDict> dictList = new ArrayList<>();
        QueryWrapper<OaSysSidebar> wrapper = new QueryWrapper<>();
        wrapper.eq(OaSysSidebar.USER_ID, userId);
        OaSysSidebar sidebar = oaSysSidebarMapper.selectOne(wrapper);
        if (sidebar != null) {
            String ids = sidebar.getDictIds();
            String[] splitVal = ids.split(",");
            List<String> asList = Arrays.asList(splitVal);
            QueryWrapper<OaSysDict> dictWrapper = new QueryWrapper<>();
            dictWrapper.in(OaSysDict.DICT_ID, asList);
            dictWrapper.orderByAsc(OaSysDict.SORT);
            dictList = oaSysDictMapper.selectList(dictWrapper);
        }
        return dictList;
    }

    /**
     * 通过id查询部门
     *
     * @param officeId
     * @return
     */
    private String getDeptByOfficeName(Long officeId) {
        //查询name
        String name = oaSysOfficeMapper.selectById(officeId).getName();
        return name;
    }

    /**
     * 通过userId查询部门
     *
     * @param userId
     * @return
     */
    private OaCUserOffice getUserIdByDept(Long userId) {
        QueryWrapper<OaCUserOffice> wrapper = new QueryWrapper<>();
        wrapper.eq(OaCUserOffice.USER_ID, userId);
        return oaCUserOfficeMapper.selectOne(wrapper);
    }

    /**
     * 通过token查询用户信息
     *
     * @param token
     * @return
     */
    private OaCUser getCUserByToken(String token) {
        QueryWrapper<OaCUser> wrapper = new QueryWrapper<>();
        wrapper.eq(OaCUser.USER_TOKEN, token);
        return oaCUserMapper.selectOne(wrapper);
    }

    /**
     * 通过userId查询用户部门
     *
     * @param userId
     * @return
     */
    private OaCWallet getWalletByUserId(Long userId) {
        QueryWrapper<OaCWallet> wrapper = new QueryWrapper<>();
        wrapper.eq(OaCWallet.USER_ID, userId);
        return oaCWalletMapper.selectOne(wrapper);
    }

    /**
     * 通过userId查询审批公务订单
     *
     * @param userId
     * @return
     */
    private List<OaCOrderApprovalOfficial> getApprovalOfficialByUserId(Long userId) {
        QueryWrapper<OaCOrderApprovalOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderApprovalOfficial.USER_ID, userId);
        queryWrapper.eq(OaCOrderApprovalOfficial.APPROVAL_STATUS, 2);
        queryWrapper.eq(OaCOrderApprovalOfficial.ORDER_STATUS, EOrderStatus.examination.getType());
        List<OaCOrderApprovalOfficial> approvalList = oaCOrderApprovalOfficialMapper.selectList(queryWrapper);
        return approvalList;
    }

    /**
     * 通过userId查询部门公务
     *
     * @param userId
     * @return
     */
    private List<OaCOrderDeptOfficial> getDeptOfficialByUserId(Long userId) {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(EOrderStatus.waitingResponse.getType());
        statusList.add(EOrderStatus.reassigned.getType());
        statusList.add(EOrderStatus.driverOrder.getType());
        statusList.add(EOrderStatus.reservationLocation.getType());
        statusList.add(EOrderStatus.driverArrived.getType());
        statusList.add(EOrderStatus.duringTrip.getType());
        statusList.add(EOrderStatus.privateItinerary.getType());
        QueryWrapper<OaCOrderDeptOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderDeptOfficial.USER_ID, userId);
        queryWrapper.in(OaCOrderDeptOfficial.ORDER_STATUS, statusList);
        List<OaCOrderDeptOfficial> approvalList = oaCOrderDeptOfficialMapper.selectList(queryWrapper);
        return approvalList;
    }

    /**
     * 通过userId查询部门公务
     *
     * @param userId
     * @return
     */
    private List<OaCOrderApprovalOfficial> getApprovalOfficialOrder(Long userId) {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(EOrderStatus.waitingResponse.getType());
        statusList.add(EOrderStatus.reassigned.getType());
        statusList.add(EOrderStatus.driverOrder.getType());
        statusList.add(EOrderStatus.reservationLocation.getType());
        statusList.add(EOrderStatus.driverArrived.getType());
        statusList.add(EOrderStatus.duringTrip.getType());
        statusList.add(EOrderStatus.privateItinerary.getType());
        QueryWrapper<OaCOrderApprovalOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderApprovalOfficial.USER_ID, userId);
        queryWrapper.in(OaCOrderApprovalOfficial.ORDER_STATUS, statusList);
        List<OaCOrderApprovalOfficial> approvalList = oaCOrderApprovalOfficialMapper.selectList(queryWrapper);
        return approvalList;
    }

    /**
     * 通过userId查询个人公务
     *
     * @param userId
     * @return
     */
    private List<OaCOrderPersonalOfficial> getPersonalOfficialByUserId(Long userId) {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(EOrderStatus.waitingResponse.getType());
        statusList.add(EOrderStatus.reassigned.getType());
        statusList.add(EOrderStatus.driverOrder.getType());
        statusList.add(EOrderStatus.reservationLocation.getType());
        statusList.add(EOrderStatus.driverArrived.getType());
        statusList.add(EOrderStatus.duringTrip.getType());
        statusList.add(EOrderStatus.privateItinerary.getType());
        QueryWrapper<OaCOrderPersonalOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderPersonalOfficial.USER_ID, userId);
        queryWrapper.in(OaCOrderPersonalOfficial.ORDER_STATUS, statusList);
        List<OaCOrderPersonalOfficial> approvalList = oaCOrderPersonalOfficialMapper.selectList(queryWrapper);
        return approvalList;
    }

    /**
     * 通过userId查询自费叫车
     *
     * @param userId
     * @return
     */
    private List<OaCOrderPersonal> getPersonalByUserId(Long userId) {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(EOrderStatus.waitingResponse.getType());
        statusList.add(EOrderStatus.reassigned.getType());
        statusList.add(EOrderStatus.driverOrder.getType());
        statusList.add(EOrderStatus.reservationLocation.getType());
        statusList.add(EOrderStatus.driverArrived.getType());
        statusList.add(EOrderStatus.duringTrip.getType());
        statusList.add(EOrderStatus.privateItinerary.getType());
        QueryWrapper<OaCOrderPersonal> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderPersonal.USER_ID, userId);
        queryWrapper.in(OaCOrderPersonal.ORDER_STATUS, statusList);
        List<OaCOrderPersonal> personalList = oaCOrderPersonalMapper.selectList(queryWrapper);
        return personalList;
    }

    /**
     * 通过userId查询审批公务订单
     *
     * @param userId
     * @return
     */
    private List<OaCOrderApprovalOfficial> getOrderApprovalOfficialByUserId(Long userId) {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(EOrderStatus.waitingResponse.getType());
        statusList.add(EOrderStatus.reassigned.getType());
        statusList.add(EOrderStatus.driverOrder.getType());
        statusList.add(EOrderStatus.reservationLocation.getType());
        statusList.add(EOrderStatus.driverArrived.getType());
        statusList.add(EOrderStatus.duringTrip.getType());
        statusList.add(EOrderStatus.normalOrderPendingPayment.getType());
        statusList.add(EOrderStatus.cancelPendingPayment.getType());
        statusList.add(EOrderStatus.cancelOrdersFeesPaid.getType());
        QueryWrapper<OaCOrderApprovalOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderApprovalOfficial.USER_ID, userId);
        // 审核通过
        queryWrapper.eq(OaCOrderApprovalOfficial.APPROVAL_STATUS, 2);
        queryWrapper.in(OaCOrderApprovalOfficial.ORDER_STATUS, statusList);
        List<OaCOrderApprovalOfficial> approvalOfficialList = oaCOrderApprovalOfficialMapper.selectList(queryWrapper);
        return approvalOfficialList;
    }

    /**
     * 通过userId查询部门公务订单
     *
     * @param userId
     * @return
     */
    private List<OaCOrderDeptOfficial> getOrderDeptByUserId(Long userId) {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(EOrderStatus.waitingResponse.getType());
        statusList.add(EOrderStatus.reassigned.getType());
        statusList.add(EOrderStatus.driverOrder.getType());
        statusList.add(EOrderStatus.reservationLocation.getType());
        statusList.add(EOrderStatus.driverArrived.getType());
        statusList.add(EOrderStatus.duringTrip.getType());
        statusList.add(EOrderStatus.normalOrderPendingPayment.getType());
        statusList.add(EOrderStatus.cancelPendingPayment.getType());
        statusList.add(EOrderStatus.cancelOrdersFeesPaid.getType());
        QueryWrapper<OaCOrderDeptOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderDeptOfficial.USER_ID, userId);
        queryWrapper.in(OaCOrderApprovalOfficial.ORDER_STATUS, statusList);
        List<OaCOrderDeptOfficial> deptOfficialList = oaCOrderDeptOfficialMapper.selectList(queryWrapper);
        return deptOfficialList;
    }

    /**
     * 通过userId查询自费叫车订单
     *
     * @param userId
     * @return
     */
    private List<OaCOrderPersonal> getOrderPersonalByUserId(Long userId) {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(EOrderStatus.waitingResponse.getType());
        statusList.add(EOrderStatus.reassigned.getType());
        statusList.add(EOrderStatus.driverOrder.getType());
        statusList.add(EOrderStatus.reservationLocation.getType());
        statusList.add(EOrderStatus.driverArrived.getType());
        statusList.add(EOrderStatus.duringTrip.getType());
        statusList.add(EOrderStatus.normalOrderPendingPayment.getType());
        statusList.add(EOrderStatus.cancelPendingPayment.getType());
        statusList.add(EOrderStatus.cancelOrdersFeesPaid.getType());
        QueryWrapper<OaCOrderPersonal> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderPersonal.USER_ID, userId);
        queryWrapper.in(OaCOrderApprovalOfficial.ORDER_STATUS, statusList);
        List<OaCOrderPersonal> personalList = oaCOrderPersonalMapper.selectList(queryWrapper);
        return personalList;
    }

    /**
     * 通过userId查询个人公务订单
     *
     * @param userId
     * @return
     */
    private List<OaCOrderPersonalOfficial> getOrderPersonalOfficialByUserId(Long userId) {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(EOrderStatus.waitingResponse.getType());
        statusList.add(EOrderStatus.reassigned.getType());
        statusList.add(EOrderStatus.driverOrder.getType());
        statusList.add(EOrderStatus.reservationLocation.getType());
        statusList.add(EOrderStatus.driverArrived.getType());
        statusList.add(EOrderStatus.duringTrip.getType());
        statusList.add(EOrderStatus.normalOrderPendingPayment.getType());
        statusList.add(EOrderStatus.cancelPendingPayment.getType());
        statusList.add(EOrderStatus.cancelOrdersFeesPaid.getType());
        QueryWrapper<OaCOrderPersonalOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderPersonalOfficial.USER_ID, userId);
        queryWrapper.in(OaCOrderApprovalOfficial.ORDER_STATUS, statusList);
        List<OaCOrderPersonalOfficial> personalOfficialList = oaCOrderPersonalOfficialMapper.selectList(queryWrapper);
        return personalOfficialList;
    }

}
